import tkinter as tk
from link import *
from PIL import ImageTk, Image
from parameter import *
import administratePage as ap

class user_info_list():
    def __init__(self, master=None):
        self.window = master
        self.window.title('用户信息界面')
        self.window.geometry('960x1040')
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=960, height=1040)
        self.page.pack()
        img = Image.open('tagagi.jpg')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Button(self.page, text='返回', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=50, y=50, anchor='nw')
        tk.Label(self.page, text='用户信息界面', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=350, y=50, anchor='nw')
        tk.Label(self.page, text='用户名', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=160, y=150, anchor='nw')
        tk.Label(self.page, text='密码', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=620, y=150, anchor='nw')

        obj = loginSearch()
        sql = user_information()

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()

        col = 200

        if len(data) == 0:
            tk.Label(self.page, text='对不起，当前已购列表为空', font=('幼圆', 20), bg='FloralWhite', fg='OliveDrab').place(x=200, y=250, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 20), bg='FloralWhite', fg='OliveDrab').place(x=140, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 20), bg='FloralWhite', fg='OliveDrab').place(x=590, y=col, anchor='nw')
            col = col + 50

        obj.close_conn()

    
    def back(self):
        self.page.destroy()
        ap.administratePage(self.window)


class showOrderList():
    def __init__(self, master=None):
        self.window = master
        self.window.title('用户信息界面')
        self.window.geometry('960x1040')
        self.create_page()

    def create_page(self):
        global image
        self.page = tk.Frame(self.window, width=960, height=1040)
        self.page.pack()
        img = Image.open('tagagi.jpg')
        image = ImageTk.PhotoImage(img)
        label_img = tk.Label(self.page, image=image)
        label_img.pack()

        tk.Button(self.page, text='返回', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin', command=self.back).place(x=50, y=50, anchor='nw')
        tk.Label(self.page, text='已购列表', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=350, y=50, anchor='nw')
        tk.Label(self.page, text='用户名', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=30, y=150, anchor='nw')
        tk.Label(self.page, text='商品类别', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=200, y=150, anchor='nw')
        tk.Label(self.page, text='商品名称', font=('楷体', 20), bg='CornflowerBlue', fg='Moccasin').place(x=500, y=150, anchor='nw')

        obj = loginSearch()
        sql = orderList()

        cursor = obj.conn.cursor()
        cursor.execute(sql)
        data = cursor.fetchall()

        col = 200

        if len(data) == 0:
            tk.Label(self.page, text='对不起，当前已购列表为空', font=('幼圆', 20), bg='FloralWhite', fg='OliveDrab').place(x=200, y=250, anchor='nw')

        for i in range(len(data)):
            tk.Label(self.page, text=data[i][0], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=30, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][1], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=240, y=col, anchor='nw')
            tk.Label(self.page, text=data[i][2], font=('幼圆', 13), bg='FloralWhite', fg='OliveDrab').place(x=330, y=col, anchor='nw')
            col = col + 30

        obj.close_conn()


    def back(self):
        self.page.destroy()
        ap.administratePage(self.window)